<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
    <link rel="stylesheet" href="../assets/app/css/app.css" />
</head>
<body style="background:#fff !important;">
<header class="bar bar-nav box_shadow head_a" style="margin-top:0px;padding-left:5px;padding-right:5px;top:0px !important;">
    <a href="javascript:SwitchBtn('default_list');" style="width:25%;" class="selected_bottom jx">即将揭晓</a>
    <a href="javascript:SwitchBtn('list_new');" style="width:25%;" class="lastnew">最新</a>
    <a href="javascript:SwitchBtn('list_renqi');" style="width:25%;" class="renqi">人气</a>
    <a href="javascript:SwitchBtn('list_price');" style="width:25%;" id="listprice">价格</a>
</header>

<section style="margin-top:33px !important;">

<div class="scroller create_goods container" style="max-width: 640px;">

<div class="goodslist" id="default_list" style="margin-top:33px;">
</div>

<div class="goodslist" id="list_new" style="margin-top:33px;display: none;">
</div>

<div class="goodslist" id="list_price" style="margin-top:33px;display: none;">
</div>

<div class="goodslist" id="list_renqi" style="margin-top:33px;display: none;">
</div>

<div style="display:none;">
<ul class="search-ul load-more">
<li><button class="btn btn-block btn-more" id="loadmore">加载更加</button></li>
</ul> 
</div>
</div>     
</section>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
var isHide = {
  downLoad : 0 //0 最新揭晓，1最新，2人气，3价格
};

//打开商品详情
function openGoods(goods_id){
	if(!goods_id) api.alert({'msg':'参数错误'});
	localData.set('goods_id',goods_id);
	api.openWin({
		name:'item',
		url:'./item.html',
		reload:true
	});
}

apiready = function(){
   var header = $api.byId('header');
	if(api.connectionType == 'none'){
		api.showProgress({
		     title : '未连接网络',
		     text : ''
		 });
		return false;
	}else{
	   api.showProgress({
	         title : '加载中',
	         text : ''
	   });
		setTimeout(function(){
			api.hideProgress();
		},15000);
	}
	
	setTimeout(function(){
		api.setRefreshHeaderInfo({
		    visible: true,
		    loadingImg: 'widget://image/refresh.png',
		    bgColor: '#fff',
		    textColor: '#333',
		    textDown: '下拉刷新...',
		    textUp: '松开刷新...',
		    showTime: true
		}, function(ret, err ){
			setTimeout(function(){
				api.refreshHeaderLoadDone();
			},15000);
			if(isHide.downLoad == 0){
				default_list();
			}else if(isHide.downLoad == 1){
				list_new();
			}else if(isHide.downLoad == 2){
				list_price();
			}else if(isHide.downLoad == 3){
				list_renqi();
			}
		});
	},500);
	
	

function default_list(){
	isHide.downLoad = 0;
    var order_type = 10; //默认排序方式
    var page = 1;
    var flag = true;
    var tag = 'list';
    
    init(order_type,page,flag,tag,api);
    
    function init(order_type,page,flag,tag,api){
        loading(api);
        ajaxData(order_type,page,flag,tag,api);
    }
    
    function loading(api){
    
    }
    
    $(window).bind('scroll', function () {
        var isLoad = true;
        var _this = document.getElementById('loadmore');
        if(getScreen().height + getScroll().top >= offsetTop(_this)){
               
        }
    });
    
    function ajaxData(order_type,page,flag,tag,api){
        order_type = 10;
        //$('.load-more').hide();
        $('.btn-more').text('加载中...');
        GetJPData(config.url+'/app.php?act=appgoodsList&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
	        api.refreshHeaderLoadDone();
            var txt = '';
            var html = '';
            for(var i=0; i < json.length; i++){
                if(json[i]['title'] == undefined){
                    //flag = false;
                    //$('.btn-more').text('已经到底了');
                    //if(json[i]['sum'] == 0){
                    //    txt = '暂无数据';
                    //}
                    break;
                }
                html += '<ul class="search-ul"><li>';
                html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url +'/'+ json[i]['thumb'] +'" /></a></div>';
                html += '<div class="search_goods_info">';
                html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
                html += '<div class="goods_info_bottom"><div class="goods_con"><progress max="100" value="'+parseInt((json[i]['canyurenshu']/json[i]['zongrenshu'])*100)+'" class="css3">';
                html += '<div class="progress-bar"></div></progress>';
                html += '<p><span class="left">总需：'+json[i]['zongrenshu']+'</span><span class="right">剩余：'+json[i]['shenyurenshu']+'</span></p>';
                html += '</div><div class="btn_buy addCart" item="'+json[i]['id']+'" onclick="addCart('+json[i]['id']+','+json[i]['yunjiage']+',1);">购买</div>';
                html += '</div></div></li></ul>';
            }
            $('#default_list').html(html);
            setTimeout(function(){
                lyzimg();
                api.hideProgress();
                if(flag == false){
                    if(txt == ''){
                    $('.btn-more').text('已经到底了');
                    }else{
                        $('.btn-more').text(txt);
                        $('.container').width($(window).width());
                    }
                }else{
                    $('.container').width('auto');
                    $('.btn-more').text('加载更多');
                    }
                $('.load-more').show();
            },1000);
        },false);
    }
    
    //加载更多
    $('#loadmore').click(function(){
        if(flag == false){
            return false;
         }
        page += 1;
        flag = true;
        if($(this).text() == '已经到底了'){
            return false;
        }else{
            loading(api);
            ajaxData(order_type,page,flag,tag,api);
        }
    });
}

default_list();

};


function list_new(){
isHide.downLoad = 1;
var order_type = 40; //默认排序方式
var page = 1;
var flag = true;
var tag = 'list';

init(order_type,page,flag,tag,api);

function init(order_type,page,flag,tag,api){
    loading(api);
    ajaxData(order_type,page,flag,tag,api);
}

function loading(api){
    api.showProgress({
        title : '加载中',
        text : ''
    });
}

function ajaxData(order_type,page,flag,tag,api){
    //$('.load-more').hide();
    $('.btn-more').text('加载中...');
    GetJPData(config.url+'/app.php?act=appgoodsList&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
    	api.refreshHeaderLoadDone();
        var txt = '';
        var html = '';
        for(var i=0; i < json.length; i++){
            if(json[i]['title'] == undefined){
                flag = false;
                $('.btn-more').text('已经到底了');
                if(json[i]['sum'] == 0){
                    txt = '暂无数据';
                }
                break;
            }
            html += '<ul class="search-ul"><li>';
            html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img  class="lazy" data-original="'+config.upload_url+'/'+ json[i]['thumb'] +'" /></a></div>';
            html += '<div class="search_goods_info">';
            html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
            html += '<div class="goods_info_bottom"><div class="goods_con"><progress max="100" value="'+parseInt((json[i]['canyurenshu']/json[i]['zongrenshu'])*100)+'" class="css3">';
            html += '<div class="progress-bar"></div></progress>';
            html += '<p><span class="left">总需：'+json[i]['zongrenshu']+'</span><span class="right">剩余：'+json[i]['shenyurenshu']+'</span></p>';
            html += '</div><div class="btn_buy addCart" item="'+json[i]['id']+'" onclick="addCart('+json[i]['id']+','+json[i]['yunjiage']+',1);">购买</div>';
            html += '</div></div></li></ul>';
        }
        setTimeout(function(){
            $('#list_new').html(html);
            lyzimg();
            api.hideProgress();
            if(flag == false){
                if(txt == ''){
                $('.btn-more').text('已经到底了');
                }else{
                    $('.btn-more').text(txt);
                    $('.container').width($(window).width());
                }
            }else{
                $('.container').width('auto');
                $('.btn-more').text('加载更多');
                }
            $('.load-more').show();
        },1000);
    });
}

//加载更多
$('#loadmore').click(function(){
    if(flag == false){
        return false;
     }
    page += 1;
    flag = true;
    if($(this).text() == '已经到底了'){
        return false;
    }else{
        loading(api);
        ajaxData(order_type,page,flag,tag,api);
    }
});

}


function list_renqi(){
isHide.downLoad = 2;
var order_type = 20; //默认排序方式
var page = 1;
var flag = true;
var tag = 'list';

init(order_type,page,flag,tag,api);

function init(order_type,page,flag,tag,api){
    loading(api);
    ajaxData(order_type,page,flag,tag,api);
}

function loading(api){
    api.showProgress({
        title : '加载中',
        text : ''
    });
}

function ajaxData(order_type,page,flag,tag,api){
    if(flag ==  false){
        return;
    }
    $('.btn-more').text('加载中...');
    GetJPData(config.url+'/app.php?act=appgoodsList&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
    	api.refreshHeaderLoadDone();
        var txt = '';
        var html = '';
        for(var i=0; i < json.length; i++){
            if(json[i]['title'] == undefined){
                flag = false;
                $('.btn-more').text('已经到底了');
                if(json[i]['sum'] == 0){
                    txt = '暂无数据';
                }
                break;
            }
            html += '<ul class="search-ul"><li>';
            html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url +'/'+ json[i]['thumb'] +'" /></a></div>';
            html += '<div class="search_goods_info">';
            html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
            html += '<div class="goods_info_bottom"><div class="goods_con"><progress max="100" value="'+parseInt((json[i]['canyurenshu']/json[i]['zongrenshu'])*100)+'" class="css3">';
            html += '<div class="progress-bar"></div></progress>';
            html += '<p><span class="left">总需：'+json[i]['zongrenshu']+'</span><span class="right">剩余：'+json[i]['shenyurenshu']+'</span></p>';
            html += '</div><div class="btn_buy addCart" item="'+json[i]['id']+'" onclick="addCart('+json[i]['id']+','+json[i]['yunjiage']+',1);">购买</div>';
            html += '</div></div></li></ul>';
        }
        setTimeout(function(){
            $('#list_renqi').html(html);
            lyzimg();
            api.hideProgress();
            if(flag == false){
                if(txt == ''){
                $('.btn-more').text('已经到底了');
                }else{
                    $('.btn-more').text(txt);
                    $('.container').width($(window).width());
                }
            }else{
                $('.container').width('auto');
                $('.btn-more').text('加载更多');
                }
            $('.load-more').show();
        },1000);
    });
    
}

//加载更多
$('#loadmore').click(function(){
    if(flag == false){
        return false;
     }
    page += 1;
    flag = true;
    if($(this).text() == '已经到底了'){
        return false;
    }else{
        loading(api);
        ajaxData(order_type,page,flag,tag,api);
    }
});

}

function list_price(){
isHide.downLoad = 3;
var order_type = 50; //默认排序方式
var page = 1;
var flag = true;
var tag = 'list';

init(order_type,page,flag,tag,api);

function init(order_type,page,flag,tag,api){
    loading(api);
    ajaxData(order_type,page,flag,tag,api);
}

function loading(api){
    api.showProgress({
        title : '加载中',
        text : ''
    });
}

function ajaxData(order_type,page,flag,tag,api){
    loading(api);
    if(flag ==  false){
        return;
    }
    $('.btn-more').text('加载中...');
    GetJPData(config.url+'/app.php?act=appgoodsList&show='+tag+'&sort='+order_type+'&page='+page,{},function(json){
    	api.refreshHeaderLoadDone();
        var txt = '';
        var html = '';
        for(var i=0; i < json.length; i++){
            if(json[i]['title'] == undefined){
                flag = false;
                $('.btn-more').text('已经到底了');
                if(json[i]['sum'] == 0){
                    txt = '暂无数据';
                }
                break;
            }
            html += '<ul class="search-ul"><li>';
            html += '<div class="search_goods_img"><a href="javascript:openGoods('+json[i]['id']+');"><img class="lazy" data-original="'+config.upload_url +'/'+ json[i]['thumb'] +'" /></a></div>';
            html += '<div class="search_goods_info">';
            html += '<p class="title_shopname"><a href="javascript:openGoods('+json[i]['id']+');">'+ json[i]['title'] +'</a></p>';
            html += '<div class="goods_info_bottom"><div class="goods_con"><progress max="100" value="'+parseInt((json[i]['canyurenshu']/json[i]['zongrenshu'])*100)+'" class="css3">';
            html += '<div class="progress-bar"></div></progress>';
            html += '<p><span class="left">总需：'+json[i]['zongrenshu']+'</span><span class="right">剩余：'+json[i]['shenyurenshu']+'</span></p>';
            html += '</div><div class="btn_buy addCart" item="'+json[i]['id']+'" onclick="addCart('+json[i]['id']+','+json[i]['yunjiage']+',1);">购买</div>';
            html += '</div></div></li></ul>';
        }
        setTimeout(function(){
            $('#list_price').html(html);
            lyzimg();
            api.hideProgress();
            if(flag == false){
                if(txt == ''){
                $('.btn-more').text('已经到底了');
                }else{
                    $('.btn-more').text(txt);
                    $('.container').width($(window).width());
                }
            }else{
                $('.container').width('auto');
                $('.btn-more').text('加载更多');
                }
            $('.load-more').show();
        },1000);
    });

}

//价格
var price = 1;
$('body').on('click','.price',function(){
    if(price == 1){
        order_type = 50;
        price = 2;
        page = 1;
    }else if(price == 2){
        order_type = 60;
        price = 1;
        page = 1;
    }
    flag = true;
    tag = 'list';
    $('#list_price').html('');
    $('.load-more').hide();
    //$('.head_a .cate').html('商品分类');
    ajaxData(order_type,page,flag,tag,api);
});

//商品分类
$('.goods_cate li a').click(function(){
    $('.head_a a').removeClass('selected_bottom');
    $('.head_a .cate').html($(this).text()).addClass('selected_bottom');
    $('.goodslist').html('');
    $('.load-more').hide();
    $('#left_overlay_aside').animate({
        'left' : 0,
    },'fast',function(){
        $('#section_container_mask').hide();
    });
    page = 1;
    flag = true;
    tag = $(this).attr('id');
    ajaxData(order_type,page,flag,tag,api);
});

//加载更多
$('#loadmore').click(function(){
    if(flag == false){
        return false;
     }
    page += 1;
    flag = true;
    if($(this).text() == '已经到底了'){
        return false;
    }else{
        loading(api);
        ajaxData(order_type,page,flag,tag,api);
    }
});

};

var isLoad = {
    listNew : true,
    listRenqi : true,
    listPrice : true,
    selected : 'default_list',
};
function SwitchBtn(page){
    if(isLoad.selected == page){
        return;
    }
    isLoad.selected = page;
    $('.goodslist').fadeOut();
    setTimeout(function(){
        $('#'+page).stop().animate({opacity : 'show'}, 'fast');
    },500);
    if(page == 'list_new' && isLoad.listNew){
        isLoad.listNew = false;
        list_new();
    }else if(page == 'list_renqi' && isLoad.listRenqi){
        isLoad.listRenqi = false;
        list_renqi();
    }else if(page == 'list_price' && isLoad.listPrice){
        isLoad.listPrice = false;
        $('#listprice').addClass('price');
        list_price();
    }
}

$('.head_a a').click(function(){
    $('.head_a a').removeClass('selected_bottom');
    $(this).addClass('selected_bottom');
});
</script>
</html>